// #include "utils/headless.h"
#include "scenes/stuntcoureur/scene.h"
#include "utils/settings.h"
#include "filesystem/be_filesystem.h"

int main(int argc, char* argv[])
{
	// setup roothpaths
#if !defined(WIN32)
	std::string home( getenv("HOME") );
	home.append( "/.stuntcoureur/" );
	BeFilesystem::Instance()->getRootPaths().push(home);
	
	// parse argv[0] for binary path
	stringstream s;
	s << argv[0];
	string path(s.str());
	size_t pos = path.find_last_of("/", path.size());
	std::stringstream buff;
	if ( pos != string::npos )
		buff << path.substr( 0, pos+1 );
	
	buff << "../share/stuntcoureur/";
	BeFilesystem::Instance()->getRootPaths().push( buff.str() );
#else
	BeFilesystem::Instance()->getRootPaths().push( "stuntcoureur/" );
#endif

	Settings *settings = Settings::Instance();

	settings->registerCVar("threads",			4, 1, 2048, false,		"background threads");
	settings->registerCVar("camerasensitivity",		100, 1, 10000, false, 		"sensitivity of the camera");
	settings->registerCVar("drawdebug",			0, 0, 1, true,			"draw bullet debug");

	settings->registerCVar("follow",			0, 0, 1, true,			"follow mode");
	settings->registerCVar("camera_follow",			0, 0, 1, true,			"3rd person camera");
	settings->registerCVar("server",			0, 0, 1, true,			"become network server");
	settings->registerCVar("client",			0, 0, 1, true,			"connect to remote server");

	settings->registerCVar("carsetting_suspensionstiffness",	500, 1, 10000, false,		"suspension stiffness");
	settings->registerCVar("carsetting_suspensiondamping",		800, 1, 10000, false,		"suspension damping");
	settings->registerCVar("carsetting_suspensioncompression",	50, 1, 10000, false,		"suspension compression");
	settings->registerCVar("carsetting_rollinfluence",		200, 1, 10000, false,		"roll influence");
	settings->registerCVar("carsetting_suspensionrestlength",	2500, 1, 10000, false,		"suspension length");
	
	settings->registerCVar("carsetting_steeringincrement",		700, 1, 10000, false,		"steering increment");
	settings->registerCVar("carsetting_steeringclamp",		200, 1, 10000, false,		"steering clamp");
	settings->registerCVar("carsetting_exponentialsteering",	250, 0, 10000, false,		"steering exponentiality");

	
	settings->registerCVar("joystick",			0, 0, 1, true,			"use joystick");
	
	settings->registerCVar("host", "127.0.0.1", "host for the client to connect to");
	settings->registerCVar("port", 32667, 1, 65536, false, "host for the client to connect to");

	settings->registerCVar("ffdev", "/dev/input/event0", "joystick force feedback device");
	
	settings->registerCVar("map", "e-road", "map to load");

	settings->doCommandLineOptions( argc, argv );

	
	// MAIN LOOP

		boost::scoped_ptr<Scene> mainscene(new Scene( argc, argv ));
		while( !mainscene->m_exitscene )
			mainscene->draw();

	return 0;

}
